package com.edu.service.impl;

import com.edu.bean.Book;
import com.edu.mapper.BookMapper;
import com.edu.service.BookService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;

    @Override
    public Page<Book> getAllBook(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Book> books = (Page<Book>) bookMapper.selectAllBook();
        return books;
    }

    @Override
    public int removeBook(int bookId) {
        return bookMapper.deleteBook(bookId);
    }

    @Override
    public Page<Book> getBookByNameBlurry(String bookName, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Book> books = (Page<Book>) bookMapper.selectBookByNameBlurry(bookName);
        return books;
    }

    @Override
    public int addBook(Book book) {
        return bookMapper.insertBook(book);
    }

    @Override
    public Book getBookById(int bookId) {
        return bookMapper.selectBookByBookId(bookId);
    }
}
